/* 代码高亮相关样式 */

/* 代码块容器 */
pre {
  position: relative;
  background-color: #282c34;
  padding: 16px;
  border-radius: 6px;
  overflow: auto;
  margin: 16px 0;
  font-family: Consolas, Monaco, 'Andale Mono', monospace;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* 代码语言标签 */
pre[data-language]:before {
  content: attr(data-language);
  position: absolute;
  top: 0;
  right: 0;
  color: white;
  background-color: rgba(0, 0, 0, 0.3);
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 0 6px 0 6px;
  text-transform: uppercase;
}

/* 代码块 */
pre code {
  background-color: transparent;
  padding: 0;
  color: #abb2bf;
  font-family: inherit;
  font-size: inherit;
  border-radius: 0;
  display: block;
}

/* 行内代码 */
:not(pre) > code, code.inline-code {
  background-color: rgba(0, 0, 0, 0.05);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: Consolas, Monaco, 'Andale Mono', monospace;
  font-size: 0.9em;
  white-space: nowrap;
  color: #e83e8c;
  margin: 0 2px;
}

/* 代码行号 */
pre.with-line-numbers {
  padding-left: 0;
  display: flex;
}

.line-numbers-container {
  margin: 0;
  padding: 16px 12px;
  border-right: 1px solid #4b5363;
  background-color: rgba(0, 0, 0, 0.2);
  text-align: right;
  user-select: none;
  min-width: 2.5em;
}

.line-number {
  display: block;
  color: #636d83;
  font-size: 0.85em;
}

/* 代码复制按钮 */
.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background-color: rgba(255, 255, 255, 0.1);
  border: none;
  color: #abb2bf;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, background-color 0.2s;
  z-index: 10;
}

pre:hover .code-copy-btn {
  opacity: 0.8;
}

.code-copy-btn:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.code-copy-btn.success {
  background-color: rgba(80, 200, 120, 0.3);
  color: #50c878;
}

.code-copy-btn.error {
  background-color: rgba(220, 50, 50, 0.3);
  color: #ff6b6b;
}

/* Markdown渲染样式增强 */
.moment-content {
  /* 链接样式 */
  & a {
    color: #409EFF;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.3s;
    position: relative;
    
    &:hover {
      border-bottom-color: #409EFF;
    }
    
    /* 外部链接指示器 */
    &[target="_blank"]::after {
      content: "↗";
      font-size: 0.85em;
      position: relative;
      top: -0.3em;
      margin-left: 2px;
      opacity: 0.7;
    }
  }
  
  /* 外部链接样式 */
  & a.external-link {
    position: relative;
    padding-right: 1.2em;
    
    &::after {
      content: "↗";
      font-size: 0.85em;
      position: absolute;
      top: 0;
      right: 0;
      opacity: 0.7;
      color: #409EFF;
      transition: transform 0.2s ease;
    }
    
    &:hover::after {
      transform: translate(2px, -2px);
    }
  }
  
  /* 列表样式 */
  & ul, & ol {
    padding-left: 20px;
    margin: 12px 0;
  }
  
  & li {
    margin-bottom: 5px;
  }
  
  /* 引用块 */
  & blockquote {
    border-left: 4px solid #409EFF;
    background-color: rgba(64, 158, 255, 0.05);
    color: #666;
    padding: 12px 16px;
    margin: 16px 0;
    font-style: italic;
  }
  
  /* 表格 */
  & table {
    border-collapse: collapse;
    width: 100%;
    margin: 16px 0;
    overflow-x: auto;
    display: block;
    
    & th, & td {
      border: 1px solid #dcdfe6;
      padding: 10px;
      text-align: left;
    }
    
    & th {
      background-color: #f5f7fa;
      font-weight: 600;
    }
    
    & tr:nth-child(even) {
      background-color: #f9f9f9;
    }
  }
  
  /* 水平线 */
  & hr {
    border: 0;
    height: 1px;
    background-image: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0));
    margin: 20px 0;
  }
  
  /* Markdown标题样式 */
  & h1, & h2, & h3, & h4, & h5, & h6 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    font-weight: 600;
    line-height: 1.25;
    color: #2c3e50;
  }
  
  & h1 {
    font-size: 2em;
    border-bottom: 1px solid #eaecef;
    padding-bottom: 0.3em;
  }
  
  & h2 {
    font-size: 1.5em;
    border-bottom: 1px solid #eaecef;
    padding-bottom: 0.3em;
  }
  
  & h3 {
    font-size: 1.25em;
  }
  
  & h4 {
    font-size: 1em;
  }
  
  & h5 {
    font-size: 0.875em;
  }
  
  & h6 {
    font-size: 0.85em;
    color: #6a737d;
  }
  
  /* 图片样式 */
  & img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1rem auto;
    border-radius: 5px;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
  }
}

/* 自定义代码主题 - 支持常见语言 */

/* 关键字 */
.hljs-keyword,
.hljs-selector-tag,
.hljs-title,
.hljs-section,
.hljs-doctag,
.hljs-name,
.hljs-strong {
  color: #c678dd;
}

/* 字符串 */
.hljs-string,
.hljs-subst {
  color: #98c379;
}

/* 数字，常量 */
.hljs-number,
.hljs-literal,
.hljs-variable,
.hljs-template-variable,
.hljs-tag .hljs-attr {
  color: #d19a66;
}

/* 函数，类名 */
.hljs-title.function_,
.hljs-class .hljs-title,
.hljs-title.class_,
.hljs-type {
  color: #61afef;
}

/* 属性，标签 */
.hljs-attr,
.hljs-attribute,
.hljs-selector-class,
.hljs-selector-attr,
.hljs-selector-pseudo {
  color: #e06c75;
}

/* 注释 */
.hljs-comment,
.hljs-quote {
  color: #5c6370;
  font-style: italic;
}

/* 内置函数 */
.hljs-built_in,
.hljs-builtin-name {
  color: #56b6c2;
}

/* 符号 */
.hljs-symbol,
.hljs-bullet,
.hljs-regexp,
.hljs-deletion {
  color: #e06c75;
}

/* 标签 */
.hljs-tag {
  color: #e06c75;
}

/* 元素 */
.hljs-meta {
  color: #61afef;
}

/* 强调 */
.hljs-emphasis {
  font-style: italic;
}

.hljs-strong {
  font-weight: bold;
}

/* 语言特定语法高亮增强 */

/* Java 特定语法高亮 */
pre[data-language="java"] .hljs-keyword {
  color: #cc99cd;
}

pre[data-language="java"] .hljs-title.class_ {
  color: #61afef;
  font-weight: bold;
}

pre[data-language="java"] .hljs-title.function_ {
  color: #56b6c2;
}

/* JavaScript/TypeScript 特定语法高亮 */
pre[data-language="javascript"] .hljs-keyword,
pre[data-language="typescript"] .hljs-keyword {
  color: #c678dd;
}

pre[data-language="javascript"] .hljs-template-string,
pre[data-language="typescript"] .hljs-template-string {
  color: #98c379;
}

pre[data-language="javascript"] .hljs-title.function_,
pre[data-language="typescript"] .hljs-title.function_ {
  color: #61aeee;
}

/* Python 特定语法高亮 */
pre[data-language="python"] .hljs-keyword {
  color: #c678dd;
}

pre[data-language="python"] .hljs-decorator {
  color: #56b6c2;
}

pre[data-language="python"] .hljs-title.function_ {
  color: #61aeee;
}

pre[data-language="python"] .hljs-title.class_ {
  color: #e5c07b;
}

/* C/C++ 特定语法高亮 */
pre[data-language="c"] .hljs-meta-keyword,
pre[data-language="cpp"] .hljs-meta-keyword {
  color: #cc99cd;
}

pre[data-language="c"] .hljs-title.function_,
pre[data-language="cpp"] .hljs-title.function_ {
  color: #56b6c2;
}

/* Markdown 特定语法高亮 */
pre[data-language="markdown"] .hljs-section {
  color: #e06c75;
  font-weight: bold;
}

pre[data-language="markdown"] .hljs-link {
  color: #61afef;
  text-decoration: underline;
}

/* SQL 特定语法高亮 */
pre[data-language="sql"] .hljs-keyword {
  color: #569cd6;
  font-weight: bold;
}

pre[data-language="sql"] .hljs-built_in {
  color: #56b6c2;
}

pre[data-language="sql"] .hljs-literal {
  color: #e06c75;
}

/* CSS/SCSS/LESS 特定语法高亮 */
pre[data-language="css"] .hljs-selector-id,
pre[data-language="scss"] .hljs-selector-id,
pre[data-language="less"] .hljs-selector-id {
  color: #e06c75;
}

pre[data-language="css"] .hljs-attribute,
pre[data-language="scss"] .hljs-attribute,
pre[data-language="less"] .hljs-attribute {
  color: #d19a66;
}

pre[data-language="css"] .hljs-selector-class,
pre[data-language="scss"] .hljs-selector-class,
pre[data-language="less"] .hljs-selector-class {
  color: #56b6c2;
}

/* JSON 特定语法高亮 */
pre[data-language="json"] .hljs-attr {
  color: #e06c75;
}

pre[data-language="json"] .hljs-string {
  color: #98c379;
}

/* 暗黑模式适配 */
@media (prefers-color-scheme: dark) {
  :not(pre) > code, code.inline-code {
    background-color: rgba(255, 255, 255, 0.1);
    color: #ff85ad;
  }
  
  pre {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  }
  
  .moment-content {
    & a {
      color: #409EFF;
    }
    
    & blockquote {
      background-color: rgba(64, 158, 255, 0.05);
      color: #bbb;
    }
    
    & table {
      & th {
        background-color: #2c2d30;
      }
      
      & th, & td {
        border-color: #3e4045;
      }
      
      & tr:nth-child(even) {
        background-color: #2a2b2e;
      }
    }
    
    & hr {
      background-image: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0));
    }
    
    & h1, & h2, & h3, & h4, & h5, & h6 {
      color: #e0e0e0;
    }
    
    & h1, & h2 {
      border-bottom-color: #3e4045;
    }
    
    & h6 {
      color: #a0a0a0;
    }
    
    & img {
      box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
    }
  }
}

/* 亮色主题适配 - 当页面使用亮色主题时 */
.light-theme pre {
  background-color: #f5f5f5;
  color: #333;
}

.light-theme pre code {
  color: #333;
}

.light-theme pre[data-language]:before {
  background-color: rgba(0, 0, 0, 0.1);
  color: #333;
}

.light-theme .line-numbers-container {
  border-right: 1px solid #ddd;
  background-color: rgba(0, 0, 0, 0.05);
}

.light-theme .line-number {
  color: #999;
}

.light-theme .code-copy-btn {
  background-color: rgba(0, 0, 0, 0.1);
  color: #666;
}

/* 自定义亮色代码高亮主题 */
.light-theme {
  & .hljs-keyword,
  & .hljs-title,
  & .hljs-section,
  & .hljs-doctag {
    color: #8959a8;
  }
  
  & .hljs-string {
    color: #718c00;
  }
  
  & .hljs-number,
  & .hljs-literal {
    color: #f5871f;
  }
  
  & .hljs-title.function_,
  & .hljs-title.class_ {
    color: #4271ae;
  }
  
  & .hljs-attr,
  & .hljs-attribute {
    color: #c82829;
  }
  
  & .hljs-comment,
  & .hljs-quote {
    color: #8e908c;
    font-style: italic;
  }
  
  & .hljs-built_in,
  & .hljs-builtin-name {
    color: #3e999f;
  }
}

/* 外部链接样式 */
.external-link {
  position: relative;
  padding-right: 1.2em;
  display: inline-flex;
  align-items: center;
  color: #409EFF !important;
  text-decoration: none;
  transition: all 0.2s ease;
}

.external-link::after {
  content: "↗";
  font-size: 0.85em;
  margin-left: 2px;
  display: inline-block;
  transition: transform 0.2s ease;
}

.external-link:hover {
  text-decoration: underline;
}

.external-link:hover::after {
  transform: translate(2px, -2px);
}

/* 暗黑模式下的外部链接 */
.dark-mode .external-link {
  color: #67c0ff !important;
}

/* 确保外部链接在代码块内不受影响 */
pre .external-link, code .external-link {
  color: inherit !important;
  text-decoration: none !important;
  padding-right: 0;
}

pre .external-link::after, code .external-link::after {
  content: "";
  display: none;
}

/* 特殊链接不处理 */
a[href^="javascript:"].external-link {
  color: inherit !important; 
  padding-right: 0;
}

a[href^="javascript:"].external-link::after {
  content: "";
  display: none;
}

/* 社交按钮不显示外部链接样式 */
.social-btn.external-link {
  padding-right: 0;
}

.social-btn.external-link::after {
  display: none;
} 